define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'gaokao/zhiyuan/index' + location.search,
                    add_url: 'gaokao/zhiyuan/add',
                    edit_url: 'gaokao/zhiyuan/edit',
                    del_url: 'gaokao/zhiyuan/del',
                    multi_url: 'gaokao/zhiyuan/multi',
                    table: 'gaokao_zhiyuan',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [{
                            checkbox: true
                        },
                        {
                            field: 'id',
                            title: __('Id'),
                            operate: false
                        },
                        {
                            field: 'type',
                            title: __('Type'),
                            searchList: {
                                "baoming": __('Type baoming'),
                                "zonghe": __('Type zonghe'),
                                "all": __('Type all')
                            },
                            formatter: Table.api.formatter.normal
                        },
                        {
                            field: 'stu_type',
                            title: __('Stu_type'),
                            searchList: {
                                "wen": __('Stu_type wen'),
                                "li": __('Stu_type li'),
                                "art": __('Stu_type art'),
                                "spo": __('Stu_type spo'),
                                "other": __('其他')
                            },
                            formatter: Table.api.formatter.normal
                        },
                        {
                            field: 'area_text',
                            title: __('Area_text')
                        },
                        {
                            field: 'school',
                            title: __('School'),
                            operate: 'LIKE'
                        },
                        {
                            field: 'grade',
                            title: __('Grade'),
                            searchList: {
                                "1": __('Grade 1'),
                                "2": __('Grade 2'),
                                "3": __('Grade 3')
                            },
                            formatter: Table.api.formatter.normal
                        },
                        {
                            field: 'identy',
                            title: __('Identy'),
                            searchList: {
                                "1": __('Identy 1'),
                                "2": __('Identy 2'),
                                "3": __('Identy 3'),
                                "4": __('Identy 4')
                            },
                            formatter: Table.api.formatter.normal
                        },
                        {
                            field: 'name',
                            title: __('Name'),
                            operate: 'LIKE'
                        },
                        {
                            field: 'mobile',
                            title: __('Mobile'),
                            operate: 'LIKE'
                        },
                        {
                            field: 'status',
                            title: __('Status'),
                            searchList: {
                                "0": __('Status 0'),
                                "1": __('Status 1')
                            },
                            formatter: Table.api.formatter.status
                        },
                        {
                            field: 'remark',
                            title: __('Remark'),
                            operate: 'LIKE'
                        },
                        {
                            field: 'createtime',
                            title: __('提交时间'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.buttons,
                            buttons: [
                                {
                                    name: 'deal',
                                    title: __('处理'),
                                    text: __('处理'),
                                    url: 'gaokao/zhiyuan/deal',
                                    classname: 'btn btn-xs btn-success btn-prompt',
                                    extend: ' data-prompt="2" data-datakey="remark" data-table-id="table" placeholder="请输入处理结果"',
                                    icon: 'fa fa-comment-o',
                                    callback: function (data) {
                                        table.bootstrapTable('refresh');
                                        return false;
                                    },
                                    visible: function(row){
                                        return row.status == 0
                                    }
                                },
                            ]
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});